package com.cmc.cloud.cmclink.doc.controller.admin;

import cn.hutool.core.bean.BeanUtil;
import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.vo.routematchcompanyvo.RouteMatchCompanyCreateReqVO;
import com.cmc.cloud.cmclink.doc.vo.routematchcompanyvo.RouteMatchCompanyPageReqVO;
import com.cmc.cloud.cmclink.doc.vo.routematchcompanyvo.RouteMatchCompanyRespVO;
import com.cmc.cloud.cmclink.doc.vo.routematchcompanyvo.RouteMatchCompanyUpdateReqVO;
import com.cmes.framework.biz.advice.annotations.UseResponsePropertyAdvice;
import com.cmes.framework.common.pojo.CommonResult;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import java.util.*;


import com.cmes.framework.common.pojo.PageResult;

import com.cmc.cloud.cmclink.doc.entity.RouteMatchCompanyDO;
import com.cmc.cloud.cmclink.doc.service.RouteMatchCompanyService;


/**
 * {table.classComment}前端接口Controller
 * 
 * @author codegen
 */
@Tag(name = "管理后台 - 路径的经营主体")
@RestController
@RequestMapping(UrlConstants.APPLICATION_URL+"/company")
@Validated
public class RouteMatchCompanyController {

    @Resource
    private RouteMatchCompanyService routeMatchCompanyService;

    @Operation(summary = "创建路径的经营主体")
    @PostMapping("/create")
    @PreAuthorize("@ss.hasPermission('doc:routeMatchCompany:add')")
    public CommonResult<Void> createRouteMatchCompany(@Valid @RequestBody RouteMatchCompanyCreateReqVO createReqVO) {
        routeMatchCompanyService.createRouteMatchCompany(createReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "更新路径的经营主体")
    @PostMapping("/update")
    @PreAuthorize("@ss.hasPermission('doc:routeMatchCompany:edit')")
    public CommonResult<Void> updateRouteMatchCompany(@Valid @RequestBody RouteMatchCompanyUpdateReqVO updateReqVO) {
        routeMatchCompanyService.updateRouteMatchCompany(updateReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "删除路径的经营主体")
    @Parameter(name = "id", description = "编号", required = true)
    @PostMapping("/delete/{id}")
    @PreAuthorize("@ss.hasPermission('doc:routeMatchCompany:delete')")
    public CommonResult<Void> deleteRouteMatchCompany(@PathVariable("id") Long id) {
        routeMatchCompanyService.deleteRouteMatchCompany(id);
        return CommonResult.success();
    }

    @Operation(summary = "获得路径的经营主体")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @GetMapping("/getById/{id}")
    public CommonResult<RouteMatchCompanyRespVO> getRouteMatchCompany(@PathVariable("id") Long id) {
        RouteMatchCompanyDO routeMatchCompany = routeMatchCompanyService.getRouteMatchCompany(id);
        return CommonResult.success(BeanUtil.copyProperties(routeMatchCompany, RouteMatchCompanyRespVO.class));
    }

    @Operation(summary = "获得路径的经营主体列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @GetMapping("/listAll")
    public CommonResult<List<RouteMatchCompanyRespVO>> getRouteMatchCompanyList(@RequestParam("ids") Collection<Long> ids) {
        List<RouteMatchCompanyDO> list = routeMatchCompanyService.getRouteMatchCompanyList(ids);
        return CommonResult.success(BeanUtil.copyToList(list,RouteMatchCompanyRespVO.class));
    }

    @Operation(summary = "获得路径的经营主体分页")
    @PostMapping("/getPage")
    @UseResponsePropertyAdvice
    @PreAuthorize("@ss.hasPermission('doc:routeMatchCompany:search')")
    public CommonResult<PageResult<RouteMatchCompanyRespVO>> getRouteMatchCompanyPage(@Valid @RequestBody RouteMatchCompanyPageReqVO pageVO) {
        PageResult<RouteMatchCompanyDO> pageResult = routeMatchCompanyService.getRouteMatchCompanyPage(pageVO);
        List<RouteMatchCompanyRespVO> results =BeanUtil.copyToList(pageResult.getList(),RouteMatchCompanyRespVO.class);
        return CommonResult.success(new PageResult<>(results,pageResult.getTotal()));
    }
}
